package com.power.sifa.correction.model;


import cn.hutool.core.util.ObjectUtil;
import com.aventrix.jnanoid.jnanoid.NanoIdUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.plf.common.domain.YesNo;
import com.plf.core.common.annotations.FieldEnumText;
import com.plf.core.common.domain.BaseModel;
import com.power.sifa.correction.model.enumeration.Tp_crc_work;
import com.power.sifa.correction.model.enumeration.Tp_crc_warn;
import com.power.sifa.correction.model.pojo.bo.CheckRuleRequestBO;
import com.power.sifa.correction.model.pojo.bo.CheckRuleResultBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
*  预警信息实体类
*/

@Entity
@ApiModel(value="预警信息")
@Data
@Table(name="Cre_warning",schema="sfapprove")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
//@IdClass(Cre_warning.Cre_warningPK.class) 用于复合组件
public class Cre_warning extends BaseModel implements Serializable {

	private static final long serialVersionUID = 1L;

    @Id
    @Setter(AccessLevel.NONE)
    @ApiModelProperty(value = "序号")
    private String id;

    @ApiModelProperty(value = "社矫人员id")
    private String perid;

    @ApiModelProperty(value = "社矫姓名")
    private String pername;

    @ApiModelProperty(value = "预警类型")
    private Integer type;

    @ApiModelProperty(value = "预警时间", example="2020-10-22 10:03:22")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date rectime;

    @ApiModelProperty(value = "拍摄纬度")
    private Double  latcamera;

    @ApiModelProperty(value = "拍摄经度")
    private Double  lngcamera;

    @ApiModelProperty(value = "预警地点")
    private String addr;

    @ApiModelProperty(value = "是否有督办")
    private Integer issup;

    @ApiModelProperty(value = "是否有再办")
    private Integer isrepeat;

    @ApiModelProperty(value = "来源公安id")
    private Integer gaid;

    @ApiModelProperty(value = "照片")
    private String photo;

    @ApiModelProperty(value = "手机纬度")
    private Double latmobile;

    @ApiModelProperty(value = "手机经度")
    private Double  lngmobile;

    @ApiModelProperty(value = "描述")
    private String describe;

    @ApiModelProperty(value = "人脸照片")
    private String facephoto;

    /**
     * 罪名
     */
    @Transient
    private String crime;

    /**
     * 处置任务id
     */
    @Transient
    private String workid;

    /**
     * 处置人
     */
    @Transient
    private String userid;

    /**
     * 处置人名称
     */
    @Transient
    private String username;

    /**
     * 单位id
     */
    @Transient
    private String deptid;

    /**
     * 单位名称
     */
    @Transient
    private String deptname;


    /**
     * 手机地址
     */
    @Transient
    private String mobileAddr;

    /**
     * 处置类型
     */
    @Transient
    private Integer worktype;


    /**
     *  预警类型文本
     */
    @Transient
    @FieldEnumText(eum="Tp_crc_warn", valuefield="type")
    private String type_text;

    /**
     *  处置类型文本
     */
//    @Transient
//    @FieldEnumText(eum="Tp_crc_work", valuefield="worktype")
//    private String worktype_text;

    /**
     *  是否有督办文本
     */
    @Transient
    @FieldEnumText(eum="yesNo", valuefield="issup")
    private String issup_text;

    /**
     *  是否有再办文本
     */
    @Transient
    @FieldEnumText(eum="yesNo", valuefield="isrepeat")
    private String isrepeat_text;



    /**
     * 状态
     */
    @Transient
    private String status;

    /**
     * 构造函数 通过规则请求数据生成一条预警信息
     * @param checkRuleRequest
     */
    public Cre_warning(CheckRuleRequestBO checkRuleRequest, CheckRuleResultBO checkRuleResult) {
        this.id = NanoIdUtils.randomNanoId();
        if (ObjectUtil.isNotNull(checkRuleRequest.getPersonInfo())) {
            this.perid = checkRuleRequest.getPersonInfo().getId();
            this.pername = checkRuleRequest.getPersonInfo().getName();
        }
        if (StringUtils.isNotEmpty(checkRuleResult.getRuleId())) {
            String firstLetter = checkRuleResult.getRuleId().substring(0, 1).toUpperCase(Locale.ROOT);
            switch (firstLetter) {
                case "A":
                    this.type = Tp_crc_warn.CROSS;
                    break;
                case "B":
                    this.type = Tp_crc_warn.LOCATIONS;
                    break;
                case "C":
                    this.type = Tp_crc_warn.LURKS;
                    break;
            }
        }
        this.rectime = checkRuleRequest.getRectime();
        this.latcamera = checkRuleRequest.getLatcamera();
        this.lngcamera = checkRuleRequest.getLngcamera();
        this.addr = checkRuleRequest.getAddr();
//        this.worktype = Tp_crc_work.UNDO;
        this.issup = YesNo.NO;
        this.isrepeat = YesNo.NO;
        this.gaid = checkRuleRequest.getId();
        this.photo = checkRuleRequest.getPhoto();
        this.describe = String.join("，", checkRuleResult.getDescribeList());
    }


    public Map<String, Object> parseMap() {
        Map<String, Object> map=new HashMap<>();
        map.put("id", this.getId());
        map.put("perid", this.getPerid());
        map.put("pername", this.getPername());
        map.put("type", this.getType());
        map.put("rectime", this.getRectime());
        map.put("latcamera", this.getLatcamera());
        map.put("lngcamera", this.getLngcamera());
        map.put("addr", this.getAddr());
//        map.put("worktype", this.getWorktype());
        map.put("issup", this.getIssup());
        map.put("isrepeat", this.getIsrepeat());
        map.put("gaid", this.getGaid());
        map.put("photo", this.getPhoto());
        map.put("latmobile", this.getLatmobile());
        map.put("lngmobile", this.getLngmobile());
        return map;
    }

    public String getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (String) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Cre_warningPK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (String)key;

        //Cre_warningPK pk = (Cre_warningPK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

}
